package com.zhongyi.dao;

import com.zhongyi.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IUserDao {

    /**
     *
     * @return
     */
    @Select("select * from user")
    @Results(id = "userMap",
            value = {
                @Result(id = true,column = "id",property = "userId"),
                    @Result(column = "username",property = "userName"),
                    @Result(column = "sex",property = "userSex"),
                    @Result(column = "birthday",property = "userBirthday"),
                    @Result(column = "address",property = "userAddress")
            })
    List<User> findAllUser();

    @Select("select * from user where id = #{id}")
    @ResultMap("userMap")
    User findById(Integer id);

    @Insert("insert into user (username,sex,birthday,address) values (#{userName},#{userSex},#{userBirthday},#{userAddress})")
    @SelectKey(keyColumn = "id",keyProperty="userId",resultType = Integer.class,before=false,statement = {"select last_insert_id()"})
    int saveUser(User user);

    @Update("update user set username=#{userName},sex=#{userSex},birthday=#{userBirthday},address=#{userAddress} where id=#{userId}")
    int updateUser(User user);

    @Delete("delete from user where id=#{userId}")
    int deleteUser(Integer id);

    @Select("select count(id) from user")
    int findTotal();

    @Select("select * from user where username=#{userName}")
    @ResultMap("userMap")
    List<User> findByName(String userName);

//    @Select("select * from user where ")
//    List<User> findByStr(String str);

}
